package ocean.chinacraft.common;

import net.minecraft.inventory.container.ContainerType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.extensions.IForgeContainerType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import ocean.chinacraft.common.world.block.function.container.FurnacePlatformBlockContainer;
import ocean.chinacraft.common.world.block.function.container.JadeWorkbenchBlockContainer;
import ocean.chinacraft.common.world.block.function.container.SericultureFrameBlockContainer;
import ocean.chinacraft.common.constants.Constants;

/**
 * 容器
 *
 * @author zhang
 * @since 2021/11/15
 */
public class ModContainer {

    public static DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS,
            Constants.MOD_ID);

    /**
     * 灶台
     */
    public static final RegistryObject<ContainerType<FurnacePlatformBlockContainer>> FURNACE_PLATFORM_BLOCK_CONTAINER =
            CONTAINERS.register("furnace_platform_block_container",
                    () -> IForgeContainerType.create(((windowId, inv, data) -> {
                        BlockPos pos = data.readBlockPos();
                        World world = inv.player.getCommandSenderWorld();
                        return new FurnacePlatformBlockContainer(windowId, world, pos, inv, inv.player);
                    })));

    /**
     * 玉石工作台
     */
    public static final RegistryObject<ContainerType<JadeWorkbenchBlockContainer>> JADE_WORKBENCH_BLOCK_CONTAINER =
            CONTAINERS.register("jade_workbench_block_container",
                    () -> IForgeContainerType.create(((windowId, inv, data) -> {
                        BlockPos pos = data.readBlockPos();
                        World world = inv.player.getCommandSenderWorld();
                        return new JadeWorkbenchBlockContainer(windowId, world, pos, inv, inv.player);
                    })));

    /**
     * 养蚕架
     */
    public static final RegistryObject<ContainerType<SericultureFrameBlockContainer>> SERICULTURE_FRAME_BLOCK_CONTAINER =
            CONTAINERS.register("sericulture_frame_block_container",
                    () -> IForgeContainerType.create(((windowId, inv, data) -> {
                        BlockPos pos = data.readBlockPos();
                        World world = inv.player.getCommandSenderWorld();
                        return new SericultureFrameBlockContainer(windowId, world, pos, inv, inv.player);
                    })));

    public static void register(IEventBus eventBus) {
        CONTAINERS.register(eventBus);
    }
}
